package com.gang.easyexcel_demo.controller;

import com.alibaba.excel.EasyExcel;
import com.gang.easyexcel_demo.entity.Teacher;
import com.gang.easyexcel_demo.listener.ReadDataListener;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
public class ReadController {

    /**
     * 读没有@ExcelProperty
     * 当没有注解时候，read的时候按照列名和实体类顺序进行赋值
     * 例如：
     * excel顺序：name=王，id=1
     * 实体类顺序：id，name
     * 读到的是：id=王，name=1
     */
    @PostMapping("/read")
    public void read(MultipartFile file) throws IOException {
        EasyExcel.read(file.getInputStream(), Teacher.class, new ReadDataListener()).sheet().doRead();
    }

}
